<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card>
          <template slot="header">
            今日销售额
          </template>
          <div>
            ￥4560
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <template slot="header">
            今日新增用户
          </template>
          <div>
            10人
          </div>
        </el-card>
      </el-col>
    </el-row>
    <br>
    <div>
        <el-card>
          <template slot="header">
            用户增长曲线
          </template>
            <div id="user" style="width: 100%;height:400px;"></div>
        </el-card>
    </div>
    <br>
    <div>
        <el-card>
          <template slot="header">
            近一个月内的销售额统计
          </template>
           <div id="sales" style="width: 100%; height: 400px;"></div>
        </el-card>
    </div>
    <br>
    <div>
        <el-card>
          <template slot="header">
            热门商品统计(销售前十的商品)
          </template>
           <div id="hot" style="width: 100%; height: 400px;"></div>
        </el-card>
    </div>
    
  </div>
  
</template>

<script>
import http from '@/core/httpRequest.js'

export default {
  data(){
    return{
      data:[],
      userXData:['a','b','c','d','e'],
      userYData:[125,23,532,231,63],
      salesXData:['a','b','c','d','e'],
      salesYData:[120,261,636,326,135],
      hotXData:[],
      hotYData:[],
    }
  },
  mounted() {
    this.category()
  },
  methods:{
    category(){
      http.get('goods/select')
      .then(res =>{
        this.data=res.data.data
        for(var i=0;i<this.data.length;i++){
          this.hotXData[i] = this.data[i].productName
          this.hotYData[i] = this.data[i].counts
        }
        this.myEcharts()
      })
    },
    myEcharts(){
      this.$echarts.init(document.getElementById('user'))
      .setOption({
        xAxis:{
          type:'category',
          data:this.userXData
        },
        yAxis:{
          type:'value'
        },
        series: [{
          data:this.userYData,
          type:'line', 
        }]
      })
      this.$echarts.init(document.getElementById('sales'))
      .setOption({
        xAxis:{
          type:'category',
          data:this.salesXData
        },
        yAxis:{
          type:'value'
        },
        series: [{
          data:this.salesYData,
          type:'line', 
        }]
      })
      this.$echarts.init(document.getElementById('hot'))
      .setOption({
        xAxis:{
          type:'category',
          data:this.hotXData
        },
        yAxis:{
          type:'value'
        },
        series: [{
          data:this.hotYData,
          type:'bar', 
        }]
      })
    }
  }
}
</script>
  
<style>

</style>